<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<div class="page_right indexpage_right">
    <div class="account_query" style="padding:0 0 30px 0;">
        <div class="account_query_listdv">
            <a href="javascript:;" id="search_data" class="cur">数据查询</a>
            <a href="javascript:;" id="search_export" >明细导出</a>
        </div>
        <p class="account_query_point">仅可查询1-7天的收入情况。</p>
        <dl>
            <dt>场地名：</dt>
            <dd>
                <select id="placeId">
                    <option value="0" selected="selected">全部场地</option>
                    <c:forEach items="${placeDeviceListVo}" var="vo">
                        <option value="${vo.placeDto.placeid}">${vo.placeDto.address}</option>
                    </c:forEach>
                </select>
            </dd>
            <dt>开始时间：</dt>
            <dd><input class="Wdate" id="stime" type="text" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'etime\',{d:-7});}',maxDate:'#F{$dp.$D(\'etime\',{d:0});}'})" ></dd>
        </dl>

        <dl>
            <dt>设备名：</dt>
            <dd>
                <select id="deviceId">
                    <option value="0">全部设备</option>
                    <c:forEach items="${deviceList}" var="device">
                        <option value="${device.deviceId}" >${device.address} - ${device.deviceName}</option>
                    </c:forEach>
                </select>
            </dd>
            <dt>结束时间：</dt>
            <dd><input class="Wdate" id="etime" type="text" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'stime\',{d:0});}',maxDate:'#F{$dp.$D(\'stime\',{d:7});}'})" ></dd>
        </dl>

        <div class="account_query_buttondv">
            <a href="javascript:;" id="search">查询</a>
            <a href="javascript:;" id="export">导出</a>
        </div>
    </div>
    <div id="showSearch" style="display: none; border-top:1px solid #eee;">
        <div id="_data" style="display: none">
            <%@ include file="/WEB-INF/jsp/web/v2/account/_rightContent1.jsp" %>
        </div>
    </div>
</div>
<script src="${basePath}resources/js/v2/accountClick.js"></script>
<script type="application/javascript">
    $("#placeId").change(function(){
        $.ajax({
            url:'${basePath}v2/account/searchPlaceDevice',
            type : 'POST',
            data : {'placeId':$("#placeId").val()},
            success: function (ret) {
                $("#deviceId option").remove();
                if(ret.result) {
                    if(ret.data.length>0){
                        $("#deviceId").append('<option value="0" selected="selected">全部设备</option>');
                        $.each(ret.data,function(n,value) {
                            $("#deviceId").append('<option value="'+value.deviceId+'">'+value.deviceName+'</option>');
                        });
                    }else{
                        $("#deviceId").append('<option value="0" selected="selected">全部设备</option>');
                    }
                }else{
                    alert(ret.info);
                }
            }
        });
    });

    //条件查询
    $("#search").click(function () {
        var place = $("#placeId").val();
        var device = $("#deviceId").val();
        var stime = $("#stime").val();
        var etime = $("#etime").val();
        if(stime=="" && etime==""){
            alert("开始时间结束时间不能为空!");
            return false;
        }
        $.ajax({
            url: "${basePath}v2/account/search",
            type: 'POST',
            data: {"stime":stime,"etime":etime,"placeId":place, "deviceId":device},
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                bindingParam(ret.AccountSummary);
                $("#showSearch").css("display","");
                $("#_data").css("display","");

                if(place!=0 && device!=0){
                    $("#editName").text("编辑");
                }else{
                    $("#editName").text("");
                }
            }
        });
    });

    //数据导出
    function exportData(){
        $("#export").click(function () {
            var place = $("#placeId").val();
            var device = $("#deviceId").val();
            var stime = $("#stime").val();
            var etime = $("#etime").val();
            if(device==0){
                alert("只能选一台设备进行导出操作!");
                return false;
            }
            if(stime=="" && etime==""){
                alert("开始时间结束时间不能为空!");
                return false;
            }

            $.ajax({
                url: "${basePath}v2/account/export",
                type: 'POST',
                data: {"stime":stime,"etime":etime,"placeid":place, "deviceid":device},
                error: function (response) {
                    $errorMsg(response);
                },
                success: function (ret) {
                    if(ret.result==true){
                        $("#export").unbind("click");
                        setTimeout(doTime, 1000*5);
                        $("#export").text("数据生成中...").css("background","#CCC");
                    }else{
                        alert(ret.info);
                    }
                }
            });
        });
    }

    exportData();

    function doTime(){
        exportData();
        $("#export").text("导出").css("background","#38adff");
    }

    $("#search_data").click(function () {
        window.location.href = "${basePath}v2/account/searchView";
    });

    $("#search_export").click(function () {
        window.location.href = "${basePath}v2/account/exportView";
    });

</script>